Skip to content

Support decimal extended type #226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 5, 2022

Conversation

DifferentialOrange
Copy link
Member

@DifferentialOrange DifferentialOrange commented Aug 30, 2022

Tarantool supports decimal type since version 2.2.1 [1]. This patch introduced the support of Tarantool decimal type in msgpack decoders and encoders. The Tarantool decimal type is mapped to the native Python decimal.Decimal type.

Tarantool decimal numbers have 38 digits of precision, that is, the total number of digits before and after the decimal point can be 38 [2]. If there are more digits arter the decimal point, the precision is lost. If there are more digits before the decimal point, error is thrown. In fact, there is also an exceptional case: if decimal starts with 0., 38 digits after the decimal point are supported without the loss of precision. msgpack encoder checks if everything is alright. If number is not a valid Tarantool decimal, the error is raised. If precision will be lost on conversion, warning is issued.

Any Tarantool decimal could be converted to a Python decimal without the loss of precision. Python decimals have its own user alterable precision (defaulting to 28 places), but it's related only to arithmetic operations: we can allocate 38-placed decimal disregarding of what decimal module configuration is used [3].

  1. Decimal (fixed point) type tarantool#692
  2. https://www.tarantool.io/ru/doc/latest/reference/reference_lua/decimal/
  3. https://docs.python.org/3/library/decimal.html

Closed #203

@DifferentialOrange DifferentialOrange changed the title Differential orange/gh 203 decimal Support decimal extended type Aug 30, 2022
@DifferentialOrange DifferentialOrange force-pushed the DifferentialOrange/gh-203-decimal branch 3 times, most recently from e19aac6 to 24a618c Compare August 31, 2022 10:37
@DifferentialOrange DifferentialOrange marked this pull request as ready for review August 31, 2022 10:50
@DifferentialOrange DifferentialOrange force-pushed the DifferentialOrange/gh-203-decimal branch 3 times, most recently from e67666a to 4205a21 Compare September 1, 2022 10:27
Copy link
Contributor

@oleg-jukovec oleg-jukovec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the patch! A few notes:

@DifferentialOrange DifferentialOrange force-pushed the DifferentialOrange/gh-203-decimal branch 2 times, most recently from 3581954 to 4e3521e Compare September 1, 2022 13:33
@DifferentialOrange DifferentialOrange force-pushed the DifferentialOrange/gh-203-decimal branch 2 times, most recently from b994b01 to 71559ad Compare September 1, 2022 17:32
Tarantool supports decimal type since version 2.2.1 [1]. This patch
introduced the support of Tarantool decimal type in msgpack decoders and
encoders. The Tarantool decimal type is mapped to the native Python
decimal.Decimal type.

Tarantool decimal numbers have 38 digits of precision, that is, the
total number of digits before and after the decimal point can be 38 [2].
If there are more digits arter the decimal point, the precision is lost.
If there are more digits before the decimal point, error is thrown. In
fact, there is also an exceptional case: if decimal starts with `0.`,
38 digits after the decimal point are supported without the loss of
precision. msgpack encoder checks if everything is alright. If number is
not a valid Tarantool decimal, the error is raised. If precision will be
lost on conversion, warning is issued.

Any Tarantool decimal could be converted to a Python decimal without the
loss of precision. Python decimals have its own user alterable precision
(defaulting to 28 places), but it's related only to arithmetic
operations: we can allocate 38-placed decimal disregarding of what
decimal module configuration is used [3].

1. tarantool/tarantool#692
2. https://www.tarantool.io/ru/doc/latest/reference/reference_lua/decimal/
3. https://docs.python.org/3/library/decimal.html

Closed #203
@DifferentialOrange DifferentialOrange force-pushed the DifferentialOrange/gh-203-decimal branch from 71559ad to 45c5b34 Compare September 5, 2022 07:42
Copy link
Contributor

@oleg-jukovec oleg-jukovec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@DifferentialOrange DifferentialOrange merged commit b0ed8f0 into master Sep 5, 2022
@DifferentialOrange DifferentialOrange deleted the DifferentialOrange/gh-203-decimal branch September 5, 2022 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support decimal
2 participants